#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> 
//父进程中调用fork创建一个子进程，两个进程同时存在，同时执行
int main()
{
	pid_t pid;
	char *message;
	int n;
	printf("fork program starting!\n");
	pid = fork();
	switch(pid)
	{
	case -1:
		perror("fork failed");	
		exit(1);
	case  0:
		message = "this is child";
		n = 5;
		break;
	default:
		message = "this is parent";
		n = 3;
		break;
	}
	for(; n > 0; n--)
	{
		puts(message);
		sleep(1);
	}
	exit(0);
}
